package cn.itsource.service.impl;

import cn.itsource.domain.Teacher;
import cn.itsource.mapper.TeacherMapper;
import cn.itsource.service.ITeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class TeacherServiceImpl implements ITeacherService {
    /** 依赖注入 */
    @Autowired
    private TeacherMapper teacherMapper;

    /**
     * 新增或修改教师数据
     * @param teacher
     */
    @Transactional
    @Override
    public void save(Teacher teacher) {
        if(teacher.getId() == null) {
            teacherMapper.save(teacher);
        } else {
            teacherMapper.update(teacher);
        }
    }

    /**
     * 根据id删除教师数据
     * @param id
     */
    @Transactional
    @Override
    public void delete(Long id) {
        teacherMapper.delete(id);
    }

    /**
     * 根据id获取教师数据
     * @param id
     * @return
     */
    @Override
    public Teacher get(Long id) {
        return teacherMapper.get(id);
    }

    /**
     * 获取全部教师数据
     * @return
     */
    @Override
    public List<Teacher> getAll() {
        return teacherMapper.getAll();
    }

    @Override
    public void batchSave(List<Teacher> teachers) {
        teacherMapper.batchSave(teachers);
    }
}
